(***********************************************************************

                    Mathematica-Compatible Notebook

This notebook can be used on any computer system with Mathematica 3.0,
MathReader 3.0, or any compatible application. The data for the notebook 
starts with the line of stars above.

To get the notebook into a Mathematica-compatible application, do one of 
the following:

* Save the data starting with the line of stars above into a file
  with a name ending in .nb, then open the file inside the application;

* Copy the data starting with the line of stars above to the
  clipboard, then use the Paste menu command inside the application.

Data for notebooks contains only printable 7-bit ASCII and can be
sent directly in email or through ftp in text mode.  Newlines can be
CR, LF or CRLF (Unix, Macintosh or MS-DOS style).

NOTE: If you modify the data for this notebook not in a Mathematica-
compatible application, you must delete the line below containing the 
word CacheID, otherwise Mathematica-compatible applications may try to 
use invalid cache data.

For more information on notebooks and Mathematica-compatible 
applications, contact Wolfram Research:
  web: http://www.wolfram.com
  email: info@wolfram.com
  phone: +1-217-398-0700 (U.S.)

Notebook reader applications are available free of charge from 
Wolfram Research.
***********************************************************************)

(*CacheID: 232*)


(*NotebookFileLineBreakTest
NotebookFileLineBreakTest*)
(*NotebookOptionsPosition[      9755,        382]*)
(*NotebookOutlinePosition[     10605,        412]*)
(*  CellTagsIndexPosition[     10561,        408]*)
(*WindowFrame->Normal*)



Notebook[{
Cell["Mathematica", "Subtitle",
  Evaluatable->False,
  CellHorizontalScrolling->False,
  TextAlignment->Center,
  AspectRatioFixed->True,
  FontFamily->"Times",
  FontSize->36,
  FontWeight->"Bold",
  FontSlant->"Italic",
  Background->GrayLevel[1]],

Cell[TextData["File Input/Output"], "Title",
  Evaluatable->False,
  CellHorizontalScrolling->False,
  TextAlignment->Center],

Cell["MATH 5037", "Subtitle",
  Evaluatable->False,
  CellHorizontalScrolling->False,
  TextAlignment->Center,
  Background->GrayLevel[1]],

Cell[TextData["Clear[\"Global`*\"]"], "Input",
  PageWidth->Infinity],

Cell[CellGroupData[{

Cell[BoxData[
    \(Finding\ a\ File\)], "Section",
  Evaluatable->False,
  FontFamily->"Times",
  FontSize->24],

Cell["\<\
Here is a technique for listing the visible files in a directory.\
\
\>", "Text"],

Cell[BoxData[
    \(Directory[]\)], "Input",
  AspectRatioFixed->True],

Cell["Complement[FileNames[],FileNames[\".*\"]]//ColumnForm", "Input",
  AspectRatioFixed->True]
}, Closed]],

Cell[CellGroupData[{

Cell["Writing Data", "Section",
  Evaluatable->False,
  FontFamily->"Times",
  FontSize->24],

Cell[TextData[
"Writing data to a file can be messy, so we will use a writeTable function we \
have defined to do this.  It is included in the tableio.m package.  We'll use \
the << operator to get it."], "Text",
  Evaluatable->False],

Cell["Using Windows 95/NT", "Subsection"],

Cell[BoxData[
    \(TraditionalForm\`<< \\\\gauss\\MATH5037\\Mathematica\\tableio.m\)], 
  "Input"],

Cell["Using NeXT", "Subsection"],

Cell["<</NeXTMount/Courses/MATH5037/Mathematica/tableio.m", "Input",
  PageWidth->Infinity],

Cell[TextData["?writeTable"], "Input",
  PageWidth->Infinity],

Cell["Using Windows 95/NT", "Subsection"],

Cell["SetDirectory[\"c:\\\\temp\"]", "Input",
  PageWidth->Infinity],

Cell["Using NeXT", "Subsection"],

Cell["SetDirectory[\"temp\"]", "Input",
  PageWidth->Infinity],

Cell[TextData["Directory[]"], "Input",
  PageWidth->Infinity],

Cell[TextData[
"m={{1,2,3},{4,3,2}};\nMatrixForm[m]\nwriteTable[\"data.txt\",m]"], "Input",
  PageWidth->Infinity],

Cell[TextData["(* display the data file *)\n!!data.txt"], "Input",
  PageWidth->Infinity]
}, Closed]],

Cell[CellGroupData[{

Cell["Reading Data", "Section",
  Evaluatable->False,
  FontFamily->"Times",
  FontSize->24],

Cell[CellGroupData[{

Cell["ReadList, Number, & RecordLists", "Section",
  Evaluatable->False],

Cell[TextData[
"Reading data from a file is easily done with the ReadList function.\n- The \
Number option specifies numeric data\n- The RecordLists options reads one \
line of the file into one sublist of the result."], "Text",
  Evaluatable->False],

Cell["\<\
mat=ReadList[\"data.txt\",Number,
\t\tRecordLists->True]\
\>", "Input",
  PageWidth->Infinity,
  Background->GrayLevel[1]],

Cell["\<\

We generally want the RecordLists option because without it we would get...\
\
\>", "Text",
  Evaluatable->False,
  FontSlant->"Italic",
  Background->GrayLevel[1]],

Cell["flatList=ReadList[\"data.txt\",Number]", "Input",
  PageWidth->Infinity,
  Background->GrayLevel[1]]
}, Open  ]],

Cell[CellGroupData[{

Cell["Word, WordSeparators, & ToExpression", "Section",
  Evaluatable->False],

Cell[TextData[
"The default delimiters between Numbers in the file are space and tab.\n\n\
However, if we read as Words instead of Numbers, we can use the \
WordSeparators options to specify other delimiters:"], "Text",
  Evaluatable->False],

Cell["?WordSeparators", "Input",
  PageWidth->Infinity,
  Background->GrayLevel[1]],

Cell[TextData["\nSuppose we have a file with comma delimiters:"], "Text",
  Evaluatable->False],

Cell["Using Windows 95/NT", "Subsection"],

Cell["SetDirectory[\"\\\\\\\\gauss\\\\MATH5037\\\\Mathematica\\\\4_lists\"]", 
  "Input",
  PageWidth->Infinity],

Cell["Using NeXT", "Subsection"],

Cell["\<\
SetDirectory[\"/NeXTMount/Courses/MATH5037/Mathematica/4_lists\"]\
\
\>", "Input",
  PageWidth->Infinity],

Cell["!!commas.txt", "Input",
  PageWidth->Infinity],

Cell["\<\
First, ReadList with Byte can be used to see exactly what exists in \
an ASCII the file.\
\>", "Text"],

Cell[BoxData[
    \(ReadList["\<commas.txt\>", Byte]\)], "Input"],

Cell["\<\
We notice that this is a DOS file because we see the CR(13) LF(10) \
pair.\
\>", "Text"],

Cell[TextData["Reading with Number won't work:"], "Text",
  Evaluatable->False],

Cell["\<\
ReadList[\"commas.txt\",Number,
\t\tRecordLists->True]
\
\>", "Input",
  PageWidth->Infinity],

Cell[TextData[
"Specifying Word and WordSeparators will allow us to read the file:"], "Text",\

  Evaluatable->False],

Cell["\<\
x=ReadList[\"commas.txt\",Word,
\t\tWordSeparators->{\",\"},
\t\tRecordLists->True]\
\>", "Input",
  PageWidth->Infinity,
  Background->GrayLevel[1]],

Cell[BoxData[
    \(FullForm[x]\)], "Input"],

Cell["\<\
However, if we are not reading this file on a DOS computer, we must \
deal with the extraneous line turnaround character. For example, On a UNIX \
system, we must specify the CR as an additional separator and on a Mac, we \
must specify the LF as an additional separator.\
\>", "Text"],

Cell["DOS Command", "Subsubsection"],

Cell[BoxData[
    \(x = 
      ReadList["\<commas.txt\>", Word, \n\t\tWordSeparators -> {"\<,\>"}, \n
        \t\tRecordLists -> True]\)], "Input"],

Cell["UNIX Command", "Subsubsection"],

Cell[BoxData[
    \(x = 
      ReadList["\<commas.txt\>", Word, \n\t\t
        WordSeparators -> {"\<,\>", "\<\r\>"}, \n\t\tRecordLists -> True]\)], 
  "Input"],

Cell["Mac Command", "Subsubsection"],

Cell[BoxData[
    \(x = 
      ReadList["\<commas.txt\>", Word, \n\t\t
        WordSeparators -> {"\<,\>", "\<\n\>"}, \n\t\tRecordLists -> True]\)], 
  "Input"],

Cell[BoxData[
    \(FullForm[x]\)], "Input"],

Cell[TextData[
"\nUnfortunately, the results are just text words, not really numeric values. \
 To prove it, let's try some arithmetic:"], "Text",
  Evaluatable->False],

Cell[TextData["x[[1,1]] + x[[1,2]]"], "Input",
  PageWidth->Infinity],

Cell["To convert to numbers, use ToExpression:", "Text",
  Evaluatable->False],

Cell[TextData["xvals=ToExpression[x]"], "Input",
  PageWidth->Infinity],

Cell[BoxData[
    \(FullForm[xvals]\)], "Input"],

Cell["Now we have real numbers:", "Text",
  Evaluatable->False],

Cell["xvals[[1,1]] + xvals[[1,2]]", "Input",
  PageWidth->Infinity]
}, Open  ]],

Cell["\<\
We could have avoided this problem by using Number with the \
RecordSeparator option rather than the WordSeparator option and remove the \
RecordList option. \
\>", "Text"],

Cell["DOS Command", "Subsubsection"],

Cell[BoxData[
    \(x = 
      ReadList["\<commas.txt\>", Number, \n\tRecordSeparators -> {"\<,\>"}, \n
        \tRecordLists -> True]\)], "Input"],

Cell["UNIX Command", "Subsubsection"],

Cell[BoxData[
    \(x = 
      ReadList["\<commas.txt\>", Number, \n\t
        RecordSeparators -> {"\<,\>", "\<\r\>"}]\)], "Input"],

Cell["Mac Command", "Subsubsection"],

Cell[BoxData[
    \(x = 
      ReadList["\<commas.txt\>", Number, \n\t
        RecordSeparators -> {"\<,\>", "\<\n\>"}]\)], "Input"],

Cell[BoxData[
    \(FullForm[x]\)], "Input"],

Cell["\<\
However, now we have a flat list. To reconstruct the proper \
structure, we use Partition.\
\>", "Text"],

Cell[BoxData[
    \(Partition[x, 3]\)], "Input"],

Cell["Reading Complex Data Structures", "Section",
  Evaluatable->False],

Cell[TextData[{
  "The file \"mike.pxm\" is a raw pixel file. If you know the internal \
structure, you can display the contents using ",
  StyleBox["Mathematica",
    FontSlant->"Italic"],
  "'s ListDensityPlot command."
}], "Text"],

Cell["\<\
stream = OpenRead[\"mike.pxm\"];
{id1,id2,width1,width2,width3,width4,
height1,height2,height3,height4,depth} = 
Read[stream,Table[Byte,{11}]];
Read[stream,Table[Byte,{14}]];
picdata = ReadList[stream,Byte];
Close[stream];\
\>", "Input",
  AspectRatioFixed->True],

Cell["\<\
pic = Partition[picdata,width4];
ListDensityPlot[Reverse[pic],
\tFrame->False,Mesh->False,
\tAspectRatio->Automatic];\
\>", "Input",
  AspectRatioFixed->True]
}, Closed]]
},
FrontEndVersion->"NeXT 3.0",
ScreenRectangle->{{0, 1053}, {0, 832}},
WindowToolbars->{},
CellGrouping->Manual,
WindowSize->{719, 452},
WindowMargins->{{Automatic, 30}, {Automatic, 6}},
PrivateNotebookOptions->{"ColorPalette"->{RGBColor, -1}},
ShowCellLabel->True,
ShowCellTags->False,
RenderingOptions->{"ObjectDithering"->True,
"RasterDithering"->False}
]


(***********************************************************************
Cached data follows.  If you edit this Notebook file directly, not using
Mathematica, you must remove the line containing CacheID at the top of 
the file.  The cache data will then be recreated when you save this file 
from within Mathematica.
***********************************************************************)

(*CellTagsOutline
CellTagsIndex->{}
*)

(*CellTagsIndex
CellTagsIndex->{}
*)

(*NotebookFileOutline
Notebook[{
Cell[1709, 49, 250, 9, 63, "Subtitle"],
Cell[1962, 60, 125, 3, 98, "Title"],
Cell[2090, 65, 138, 4, 51, "Subtitle"],
Cell[2231, 71, 69, 1, 24, "Input"],

Cell[CellGroupData[{
Cell[2325, 76, 112, 4, 57, "Section"],
Cell[2440, 82, 91, 3, 33, "Text"],
Cell[2534, 87, 70, 2, 30, "Input"],
Cell[2607, 91, 96, 1, 30, "Input"]
}, Closed]],

Cell[CellGroupData[{
Cell[2740, 97, 92, 3, 37, "Section"],
Cell[2835, 102, 234, 4, 46, "Text"],
Cell[3072, 108, 41, 0, 43, "Subsection"],
Cell[3116, 110, 99, 2, 26, "Input"],
Cell[3218, 114, 32, 0, 43, "Subsection"],
Cell[3253, 116, 91, 1, 24, "Input"],
Cell[3347, 119, 61, 1, 24, "Input"],
Cell[3411, 122, 41, 0, 43, "Subsection"],
Cell[3455, 124, 68, 1, 24, "Input"],
Cell[3526, 127, 32, 0, 43, "Subsection"],
Cell[3561, 129, 62, 1, 24, "Input"],
Cell[3626, 132, 61, 1, 24, "Input"],
Cell[3690, 135, 114, 2, 48, "Input"],
Cell[3807, 139, 89, 1, 36, "Input"]
}, Closed]],

Cell[CellGroupData[{
Cell[3933, 145, 92, 3, 37, "Section"],

Cell[CellGroupData[{
Cell[4050, 152, 72, 1, 52, "Section"],
Cell[4125, 155, 250, 4, 62, "Text"],
Cell[4378, 161, 132, 5, 36, "Input"],
Cell[4513, 168, 175, 7, 46, "Text"],
Cell[4691, 177, 106, 2, 24, "Input"]
}, Open  ]],

Cell[CellGroupData[{
Cell[4834, 184, 77, 1, 52, "Section"],
Cell[4914, 187, 241, 4, 62, "Text"],
Cell[5158, 193, 83, 2, 24, "Input"],
Cell[5244, 197, 95, 1, 46, "Text"],
Cell[5342, 200, 41, 0, 43, "Subsection"],
Cell[5386, 202, 112, 2, 24, "Input"],
Cell[5501, 206, 32, 0, 43, "Subsection"],
Cell[5536, 208, 115, 4, 24, "Input"],
Cell[5654, 214, 52, 1, 24, "Input"],
Cell[5709, 217, 112, 3, 30, "Text"],
Cell[5824, 222, 65, 1, 25, "Input"],
Cell[5892, 225, 98, 3, 30, "Text"],
Cell[5993, 230, 79, 1, 30, "Text"],
Cell[6075, 233, 103, 5, 48, "Input"],
Cell[6181, 240, 117, 3, 30, "Text"],
Cell[6301, 245, 159, 6, 48, "Input"],
Cell[6463, 253, 44, 1, 24, "Input"],
Cell[6510, 256, 295, 5, 62, "Text"],
Cell[6808, 263, 36, 0, 40, "Subsubsection"],
Cell[6847, 265, 147, 3, 51, "Input"],
Cell[6997, 270, 37, 0, 40, "Subsubsection"],
Cell[7037, 272, 160, 4, 51, "Input"],
Cell[7200, 278, 36, 0, 40, "Subsubsection"],
Cell[7239, 280, 160, 4, 51, "Input"],
Cell[7402, 286, 44, 1, 24, "Input"],
Cell[7449, 289, 168, 3, 46, "Text"],
Cell[7620, 294, 69, 1, 24, "Input"],
Cell[7692, 297, 78, 1, 30, "Text"],
Cell[7773, 300, 71, 1, 24, "Input"],
Cell[7847, 303, 48, 1, 24, "Input"],
Cell[7898, 306, 63, 1, 30, "Text"],
Cell[7964, 309, 67, 1, 24, "Input"]
}, Open  ]],
Cell[8046, 313, 182, 4, 46, "Text"],
Cell[8231, 319, 36, 0, 40, "Subsubsection"],
Cell[8270, 321, 147, 3, 51, "Input"],
Cell[8420, 326, 37, 0, 40, "Subsubsection"],
Cell[8460, 328, 132, 3, 38, "Input"],
Cell[8595, 333, 36, 0, 40, "Subsubsection"],
Cell[8634, 335, 132, 3, 38, "Input"],
Cell[8769, 340, 44, 1, 24, "Input"],
Cell[8816, 343, 114, 3, 30, "Text"],
Cell[8933, 348, 48, 1, 24, "Input"],
Cell[8984, 351, 72, 1, 52, "Section"],
Cell[9059, 354, 233, 6, 46, "Text"],
Cell[9295, 362, 273, 9, 96, "Input"],
Cell[9571, 373, 168, 6, 60, "Input"]
}, Closed]]
}
]
*)




(***********************************************************************
End of Mathematica Notebook file.
***********************************************************************)

